<template>
    <div>
        <el-dialog
            :title="title"
            :visible.sync="dialogVisible"
            @closed="close"
            top="10px"
            :close-on-click-modal="false"
            @open="open"
            width="700px">
                <el-form :model="formdata" label-width="120px" ref="addform"  :rules="rules">
                    <el-form-item label="教室名称：" prop="bCR_Name">
                        <el-input type="text" v-model.trim="formdata.bCR_Name" placeholder="请输入教室名称"></el-input>
                    </el-form-item>
                    <el-form-item label="面积：" prop="bCR_Area">
                        <el-input type="text" v-model.trim="formdata.bCR_Area" placeholder="请输入教室面积"></el-input>
                    </el-form-item>
                    <el-form-item label="投入使用时间" prop="bCR_Time">
                        <el-date-picker
                            v-model="formdata.bCR_Time"
                            @change="change"
                            value-format="yyyy-MM-dd"
                            type="date"
                            placeholder="选择日期">
                        </el-date-picker>
                    </el-form-item>
                    <!-- <el-form-item label="摄像头绑定：" prop="bCR_Camera">
                        <el-input type="text" v-model.trim="formdata.bCR_Camera" placeholder="请输入"></el-input>
                    </el-form-item> -->

                    <el-form-item label="配置清单：" prop="bCR_QD">
                        <!-- <quill-editor v-model="formdata.bCR_QD"
                            style="line-height:0px;"
                            ref="myQuillEditor"
                            :options="editorOption"
                            @blur="onEditorBlur($event)"
                            @focus="onEditorFocus($event)"
                            @ready="onEditorReady($event)">
                        </quill-editor> -->
                        <ele-editor editorId=“classromeEditor” v-model="formdata.bCR_QD"></ele-editor>
                    </el-form-item>
                </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="save">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
// 添加康复记录
import {addClassRoom,editClassRoom} from '@/api/index.js'
import eleEditor from '@/components/editor.vue'
export default {
    components:{
        eleEditor
    },
    data() {
        return {
            dialogVisible:false,
            formdata:{
                bCR_Name:'',
                bCR_Area:'',
                bCR_Time:'',
                bCR_QD:"",
                bCR_Camera:""
            },
            rules: {
                bCR_Name: [
                    { required: true, message: '教室名称不能为空', trigger: 'blur' }
                ],
                bCR_Area: [
                    { required: true, message: '教室面积不能为空', trigger: 'blur' }
                ]
            }
        }
    },
    props:{
        title:{
            type:String,
            default:'新增教室'
        },
        eidtinfo:{
            type:null
        }
    },
    methods:{
        save(){
            this.$refs.addform.validate((valid) => {
                if (valid) {
                    if(this.eidtinfo) {
                        editClassRoom({...this.formdata,bCID:this.eidtinfo.CID}).then((res) => {
                            if(res) {
                                if(res.code == 200) {
                                    this.$util.tipsMsg('success','修改成功！');
                                    this.dialogVisible = false;
                                    this.$emit('addsuccess',true);
                                } else {
                                    this.$util.tipsMsg('error',res.message);
                                }
                            }
                        }).catch((err) => {

                        })
                    } else {
                        addClassRoom(this.formdata).then((res) => {
                            if(res) {
                                if(res.code == 200) {
                                    this.$util.tipsMsg('success','添加成功！');
                                    this.dialogVisible = false;
                                    this.$emit('addsuccess',true);
                                } else {
                                    this.$util.tipsMsg('error',res.message);
                                }
                            }
                        }).catch((err) => {

                        })
                    }
                } else {
                    return false;
                }
            })
            
        },
        change(e) {
            console.log(e)
        },
        open(){
            this.$nextTick(() =>{
                if(this.eidtinfo) {
                    this.formdata.bCR_Name = this.eidtinfo.CR_Name || '';
                    this.formdata.bCR_Area = this.eidtinfo.CR_Area || '';
                    this.formdata.bCR_Time = this.eidtinfo.CR_Time;
                    this.formdata.bCR_QD = this.eidtinfo.CR_QD || '';
                    this.formdata.bCR_Camera = this.eidtinfo.CR_Camera || '';
                }
            })
            
        },
        onEditorBlur(quill) {
        },
        onEditorFocus(quill) {
        },
        onEditorReady(quill) {
        },
        close(){
            this.$refs.addform.resetFields();
        }
    }
}
</script>
<style lang="less">

</style>
